move-to

 

move-to allows a turtle to set its x and y coordinates to be the same as another turtle or patch without altering the turtle's other variables (e.g., heading, color, size). The format of this is move-to *insert agent here*. For example:

ask rabbits [
    move-to one-of patches with [pcolor = green]
    eat-grass
]

This paragraph of code would make each rabbit move to the exact location of a randomly picked green patch. Note that if the target turtle or patch does not exist, the model will give an error.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the move-to primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the move-to primitive:
 
 
Similar primitives:
setxy

set the position of a turtle (in terms of X and Y coordinates)

Read more
face

Turn to face a specific agent.

Read more
distance

Find the distance from the caller to an agent.

Read more
 
Learn another primitive